package com.example.administrator.zhongyichou.fragment;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.example.administrator.zhongyichou.activity.ChildrenHelpActivity;
import com.example.administrator.zhongyichou.activity.ElderlyHelpActivity;
import com.example.administrator.zhongyichou.activity.JoinActionActivity;
import com.example.administrator.zhongyichou.activity.MillionsHelpActivity;
import com.example.administrator.zhongyichou.activity.MutualPublicityActivity;
import com.example.administrator.zhongyichou.activity.YoungHelpActivity;
import com.example.administrator.zhongyichou.adapter.MutualAidAdapter;
import com.example.administrator.zhongyichou.Bean.BaseEventBean;
import com.example.administrator.zhongyichou.base.BaseFragment;
import com.example.administrator.zhongyichou.net.NetConfig;
import com.example.administrator.zhongyichou.net.core.RequestHttpLoader;
import com.example.administrator.zhongyichou.net.protocol.MutualProtocol;
import com.example.administrator.zhongyichou.net.core.HttpLoader;
import com.example.administrator.zhongyichou.R;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 第五版新加
 * Created by lichenyu on 2017/11/20.
 * 描述：互助
 */

public class MutualAidFragment extends BaseFragment<MutualProtocol> implements View.OnClickListener, MutualAidAdapter.OnItemClick {
    ImageView imgTop;
    LinearLayout llBtn;
    LinearLayout llBtn1;
    LinearLayout llBtn2;
    @BindView(R.id.listview)
    ListView listview;
    MutualAidAdapter adapter;

    @Override
    protected void responseData(MutualProtocol mGsonBaseProtocal) {
        adapter = new MutualAidAdapter(getActivity(), mGsonBaseProtocal.getData());
        listview.setAdapter(adapter);
        adapter.setOnItemClick(this);
    }

    @Override
    protected HttpLoader initHttpLoader() {
        RequestHttpLoader requestHttpLoader = new RequestHttpLoader(MutualProtocol.class);
        requestHttpLoader.setParams(NetConfig.MUTUAL_LIST, new HashMap<String, String>());
        return requestHttpLoader;
    }

    @Override
    protected boolean isRequestData() {
        return true;
    }

    @Override
    protected View initContentView() {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.mutual_aid_fragment, null);
        ButterKnife.bind(this, view);
        initList();
        return view;
    }

    private void initList() {
        View head = LayoutInflater.from(getContext()).inflate(R.layout.mutual_aid_fragment_head, null);
        imgTop = (ImageView) head.findViewById(R.id.img_top);
        llBtn = (LinearLayout) head.findViewById(R.id.ll_btn);
        llBtn1 = (LinearLayout) head.findViewById(R.id.ll_btn1);
        llBtn2 = (LinearLayout) head.findViewById(R.id.ll_btn2);
        llBtn.setOnClickListener(this);
        llBtn1.setOnClickListener(this);
        llBtn2.setOnClickListener(this);
        listview.addHeaderView(head);
    }

    @Override
    public boolean onEventBus(BaseEventBean baseEventBean) {

        return false;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_btn://为家人加入
                Intent intent = new Intent(getActivity(), JoinActionActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_btn1://互助充值
                Intent intent1 = new Intent(getActivity(), JoinActionActivity.class);
                startActivity(intent1);
                break;
            case R.id.ll_btn2://互助公示
                Intent intent2 = new Intent(getActivity(), MutualPublicityActivity.class);
                startActivity(intent2);
                break;
        }
    }

    //加入
    @Override
    public void onClick(int position) {
        switch (position) {
            case 0://百万终身大病互助行动
                Intent intent = new Intent(getActivity(), MillionsHelpActivity.class);
                startActivity(intent);
                break;
            case 1://少儿大病互助行动
                Intent intent2 = new Intent(getActivity(), ChildrenHelpActivity.class);
                startActivity(intent2);
                break;
            case 2://中青年大病互助行动
                Intent intent1 = new Intent(getActivity(), YoungHelpActivity.class);
                startActivity(intent1);
                break;
            case 3://老年大病互助行动
                Intent intent3 = new Intent(getActivity(), ElderlyHelpActivity.class);
                startActivity(intent3);
                break;
        }
    }
}
